(in-package :ws-sql)
;;;; $Id: broker.lisp 2467 2007-06-04 13:31:04Z mev $

(defparameter *local* 
  (list "<root/>"))
;;   (macrolet ((mklist (&rest args)
;; 	       `(if (listp ,args)
;; 		   args
;; 		   (list ,@args))))
;;     (mklist "<root/>")))

(defun get (iri)
  (let ((local (copy-list *local*)))
    (let ((representation (rest-get iri)))
      (if (assoc iri local)
	  (modify-grouple iri representation)
	  (create-grouple iri representation)))
    representation))
	
(defun put (local iri)
  (append-grouple local iri))

(defun rest-get (iri)
  (with-open-file (rest-substrate :filespec (resolve-filepath iri)
    (read read-substrate))))

(defun rest-put (iri representation)
  (with-open-file (rest-substrate :filespec (resolve-filepath iri)
    (write representation rest-substrate)))

(defun modify-grouple (local contents)
  (setf (assoc iri local) (copy-list contents)))

(defun append-grouple (local iri)
  (setf local (append local iri)))

(defun resolve-filepath (iri)
  (merge-pathnames iri)


